// Copyright (C) CompatibL Technologies LLC. All rights reserved.
// This code contains valuable trade secrets and may be used, copied,
// stored, or distributed only in accordance with a written license
// agreement and with the inclusion of this copyright notice. 

#region File Info
// File       : CurrentConfiguration.cs
// Description: ChordCreator.Services.ConfigurationServices.CurrentConfiguration component implementation.
// Package    : ChordCreator.Services.ConfigurationServices
//
#endregion

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ChordCreator.Services.ConfigurationServices
{
    /// <summary>
    /// Stores currently selected configuration
    /// </summary>
    class CurrentConfiguration
    {
        private static CurrentConfiguration instance_;
        public static CurrentConfiguration Instance
        {
            get { if (instance_ == null) instance_ = new CurrentConfiguration(); return instance_; }
        }

        private Dictionary<Note, string> scalePresentation_;
        private Note tonic_;

        public void SetScale(string[] scaleDisplaying, Note tonic)
        {
            tonic_ = tonic;
            if (scaleDisplaying.Count() != 12)
            {
                throw new ArgumentException("scaleDisplaying must be 12 counting");
            }
            scalePresentation_ = new Dictionary<Note, string> { {tonic, scaleDisplaying[0]} };
            int index = 1;
            tonic++;
            while ((int)tonic < 12)
            {
                scalePresentation_.Add(tonic, scaleDisplaying[index]);
                tonic++;
                index++;
            }
            tonic = 0;
            while (tonic != tonic_)
            {
                scalePresentation_.Add(tonic, scaleDisplaying[index]);
                tonic++;
                index++;
            }
        }

        public string GetNotePresentation(Note note)
        {
            if (scalePresentation_ == null)
            {
                return note.ToString();
            }
            return scalePresentation_[note];
        }



        private CurrentConfiguration()
        {

        }

        public List<Note> GetNotesFromPresentations(List<string> notes)
        {
            List<Note> result = new List<Note>();
            foreach (string str in notes)
            {
                foreach (var pair in scalePresentation_)
                {
                    if (pair.Value == str)
                    {
                        result.Add(pair.Key);
                    }
                }
            }
            return result;
        }
    }
}
